<template>
  <div class="ratingselect">
    <div class="selectType border-1px">
      <span class="block positive" :class="{'active':selectType===2}" @click="select(2,$event)">
        {{selectText.all}}
        <span class="count">{{ratings.length}}</span>
      </span>
      <span class="block positive" :class="{'active':selectType===0}" @click="select(0,$event)">
        {{selectText.positive}}
        <span class="count">{{positives.length}}</span>
      </span>
      <span class="block negative" :class="{'active':selectType===1}" @click="select(1,$event)">
        {{selectText.negative}}
        <span class="count">{{negatives.length}}</span>
      </span>
    </div>
    <div class="switch" @click="switchChange">
      <i class="icon-check_circle" :class="{'active':onlyContent===true}"></i>
      <span class="text">只看有内容的评价</span>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  const ALL = 2
  const Negative = 1
  const Positive = 0
  export  default{
    props: {
      ratings: {
        type: Array,
        default(){
          return []
        }
      },
      selectType: {
        type: Number,
        default: ALL
      },
      selectText: {
        type: Object,
        default(){
          return {
            all: '全部',
            positive: '满意',
            negative: '不满意'
          }
        }
      },
      onlyContent: {
        type: Boolean,
        default: false
      }
    },
    data(){
      return {
        type: this.selectType,
        myswitch: this.onlyContent
      }
    },
    computed: {
      positives(){
        return this.ratings.filter((rating) => {
          return rating.rateType === Positive
        })
      },
      negatives(){
        return this.ratings.filter((rating) => {
          return rating.rateType === Negative
        })
      }
    },
    methods: {
      select(value, event){
        if (!event._constructed) {
          return
        }
        this.type = value
        this.$emit('changeselectType', value)
      },
      switchChange(event){
        if (!event._constructed) {
          return
        }
          console.log('click')
        this.myswitch = !this.myswitch
        let value = this.myswitch
        this.$emit('changeSwitch', value)
      }
    }
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../common/stylus/mixin.styl"
  .ratingselect
    .selectType
      margin: 0 18px
      padding: 18px 0
      border-1px(rgba(7, 17, 27, 0.1))
      color: rgb(77, 85, 93)
      font-size: 0
      .block
        display: inline-block
        margin-right: 8px
        padding: 8px 12px
        border-radius: 1px
        line-height: 16px
        font-size: 12px
        &.positive
          background: rgba(0, 160, 220, 0.2)
          &.active
            background: rgb(0, 160, 220)
            color: #fff
        &.negative
          background: rgba(77, 85, 93, 0.2)
          &.active
            background: rgb(77, 85, 93)
            color: #fff
        .count
          font-size: 8px

    .switch
      padding: 12px 18px
      border-bottom: 1px solid rgba(7, 17, 27, 0.1)
      line-height: 24px
      color: rgb(147, 153, 159)
      font-size: 0
      .icon-check_circle
        display: inline-block
        margin-right: 4px
        vertical-align: top
        font-size: 24px
        &.active
          color: #00b43c
      .text
        display: inline-block
        font-size: 12px
</style>
